package com.zsw.procure_system.controller;

import com.alibaba.fastjson2.JSONObject;
import com.zsw.procure_system.pojo.result.ApiResult;
import com.zsw.procure_system.service.UserinfoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.io.InputStream;

@RestController
@Slf4j
@CrossOrigin
@RequestMapping("/permission")
public class PermissionController {
    @Autowired
    private UserinfoService userinfoService;

    @GetMapping("/permission")
    public ApiResult<JSONObject> getPermission(String token) throws IOException {
        if (token.equals("admin")) {
            InputStream resourceAsStream = this.getClass().getResourceAsStream("/json/admin.json");
            String s = IOUtils.toString(resourceAsStream);
            JSONObject jsonObject = JSONObject.parseObject(s);
            return ApiResult.ok(jsonObject);
        }
        InputStream resourceAsStream = this.getClass().getResourceAsStream("/json/vip.json");
        String s = IOUtils.toString(resourceAsStream);
        JSONObject jsonObject = JSONObject.parseObject(s);
        return ApiResult.ok(jsonObject);

    }

}
